﻿using UnityEngine;
using System.Collections.Generic;
using Dict.Config;
using Dict.Blo;
using Dict.DataModel;
using UI;
using Dict;
using ProtoBuf.Message;

public static class CommonMethod
{
    public const double tableAttributeConvert = 0.01;
    public const double tableAttributeConvert_anti = 100;
    /// <summary>
    /// 修改物体层级
    /// </summary>
    /// <param name="tran"></param>
    /// <param name="layerName"></param>
    public static void ChangeLayer(Transform tran, string layerName)
    {
        int layer = LayerMask.NameToLayer(layerName);
        ChangeLayer(tran, layer);
    }

    public static void ChangeParticleLayer(Transform tran, string layerName)
    {
        int layer = LayerMask.NameToLayer(layerName);
        tran.gameObject.layer = layer;

        var parits = tran.GetComponentsInChildren<ParticleSystem>();
        foreach (var tr in parits)
        {
            ChangeLayer(tr.transform, layer);
        }

    }

    /// <summary>
    /// 修改物体层级
    /// </summary>
    /// <param name="tran"></param>
    /// <param name="layerName"></param>
    public static void ChangeLayer(Transform tran, int layer)
    {
        tran.gameObject.layer = layer;
        //foreach (Transform t in tran)
        //{
        //    ChangeLayer(t, layer);
        //}
        for(int i = 0; i < tran.childCount;++i)
        {
            ChangeLayer(tran.GetChild(i), layer);
        }
    }

    public static string GetTokenText(string type)
    {
        switch (type)
        {
            case Dict.Config.TableConst.coin:
                return TableTextBlo.GetText("coin");
            case Dict.Config.TableConst.diamond:
                return TableTextBlo.GetText("diamond");
            case Dict.Config.TableConst.score:
                return TableTextBlo.GetText("offer_score");
            case Dict.Config.TableConst.popularity:
                return TableTextBlo.GetText("prestige");
            case Dict.Config.TableConst.point:
                return TableTextBlo.GetText("strategy_score");
            case Dict.Config.TableConst.light:
                return TableTextBlo.GetText("the_light_of_retention：");
            default:
                return "";
        }
    }

    public static string GetObjectDescTextId(string id)
    {
        //if (id.StartsWith(Dict.Config.TableConst.coin))
        //    return Dict.Config.TableConst.coin;
        //else if (id.StartsWith(Dict.Config.TableConst.diamond))
        //    return Dict.Config.TableConst.diamond;
        //else if (id.StartsWith(Dict.Config.TableConst.popularity))
        //    return "prestige";

        return "desc_" + id;
    }
    public static string GetObjectNameTextId(string id)
    {
        if (id.StartsWith(Dict.Config.TableConst.coin))
            return Dict.Config.TableConst.coin;
        else if (id.StartsWith(Dict.Config.TableConst.contribution))
            return "union_item_contribute";
        else if (id.StartsWith(Dict.Config.TableConst.diamond))
            return Dict.Config.TableConst.diamond;
        else if (id.StartsWith(Dict.Config.TableConst.popularity))
            return "prestige";
        else if (id.StartsWith(Dict.Config.TableConst.score))
            return "reward_score2";
        else if (id.StartsWith(Dict.Config.TableConst.point))
        {
            return "strategy_score";
        }
        else if (id.StartsWith(Dict.Config.TableConst.light))
        {
            return "the_light_of_retention";
        }
        else if (id.StartsWith(Dict.Config.TableConst.energy))
        {
            return "naili";
        }
        else if (id.StartsWith(Dict.Config.TableConst.war))
        {
            TableHero herodata = DictHeroBlo.GetTableHero(id);
            return herodata.name;
        }
        else if (id.StartsWith(Dict.Config.TableConst.frag_war))
        {
            id = id.Substring(5);
            TableHero herodata = DictHeroBlo.GetTableHero(id);
            return herodata.name;
        }
        else if(id.StartsWith(Dict.Config.TableConst.frag_pet))
        {
            TablePet petData = DictPetBlo.GetTablePet(id);
            return petData.name;
        }
        else if (id.StartsWith(Dict.Config.TableConst.frag_trea))
        {
            TableFrag fragdata = DictFragBlo.GetTableFrag(id);
            return "name_" + fragdata.target;
        }
        else if (id.StartsWith(Dict.Config.TableConst.equip))
        {
            id = DictEquipBlo.GetTableEquip(id).id;
        }
        else if (id.StartsWith(Dict.Config.TableConst.frag_equip))
        {
            id = id.Substring(5);
            id = DictEquipBlo.GetTableEquip(id).id;
        }
        return "name_" + id;
    }
    /// <summary>
    /// 获取碎片名称
    /// </summary>
    /// <param name="fragId"></param>
    /// <returns></returns>
    public static string GetFragName(string fragId)
    {
        if (fragId.StartsWith(TableConst.frag_trea))
        {
            string n = "name_" + fragId.Substring(5, fragId.Length - 7);
            return TableTextBlo.GetText(n) + TableTextBlo.GetText("fragment") + fragId[fragId.Length - 1];
        }
        else if (fragId.StartsWith(TableConst.frag_war))
        {
            string n = fragId.Substring(5);
            return TableTextBlo.GetText(DictHeroBlo.GetTableHero(n).name) + TableTextBlo.GetText("fragment");
        }
        else if (fragId.StartsWith(TableConst.frag_equip))
        {
            string n = "name_" + fragId.Substring(5);
            return TableTextBlo.GetText(n) + TableTextBlo.GetText("fragment");
        }
        else if (fragId.StartsWith(TableConst.frag_pet))
        {
            string n = "name_" + fragId.Substring(5);
            return TableTextBlo.GetText(n) + TableTextBlo.GetText("fragment");
        }
        Debug.LogError("Error frag id");
        return null;
    }
    /// <summary>
    /// 通过id获取物品类型，图标和品质
    /// </summary>
    /// <param name="id"></param>
    /// <param name="itemType"></param>
    /// <param name="iconName"></param>
    /// <param name="quality"></param>
    public static void IconParse(string id, out UIItemType itemType, out string iconName, out int quality)
    {
        iconName = "";
        quality = 0;
        if (id.StartsWith(TableConst.war))
        {
            itemType = UIItemType.Hero;
            var th = DictDataManager.Instance.tableHeroDao.GetById(id);
            if (th != null)
            {
                iconName = th.iconName;
                quality = th.quality;
            }
        }
        else if (id.StartsWith(TableConst.trea))
        {
            itemType = UIItemType.Treasure;
            var tt = DictDataManager.Instance.tableTreasureDao.GetById(id);
            if (tt != null)
            {
                iconName = tt.icon;
                quality = tt.quality;
            }
        }
        else if (id.StartsWith(TableConst.item))
        {
            itemType = UIItemType.Item;
            var ti = DictDataManager.Instance.tableItemDao.GetById(id);
            if (ti != null)
            {
                iconName = ti.icon;
                quality = -1;
            }
        }
        else if (id.StartsWith(TableConst.equip))
        {
            var te = DictDataManager.Instance.tableEquipDao.GetById(id);
            itemType = UIItemType.Equip;
            if (te != null)
            {
                iconName = te.icon;
                quality = te.quality;
            }
        }

        else if (id.StartsWith(TableConst.frag_equip))
        {
            itemType = UIItemType.EquipFrag;
            var tablefrag = DictDataManager.Instance.tableFragDao.GetById(id);
            if (tablefrag != null)
            {
                var target_id = tablefrag.target;
                var te = DictDataManager.Instance.tableEquipDao.GetById(target_id);
                if (te != null)
                {
                    iconName = te.icon;
                    quality = te.quality;
                }
            }
        }

        else if (id.StartsWith(TableConst.frag_trea))
        {
            itemType = UIItemType.TreasureFrag;
            var tablefrag = DictDataManager.Instance.tableFragDao.GetById(id);
            if (tablefrag != null)
            {
                var target_id = tablefrag.target;
                var tt = DictDataManager.Instance.tableTreasureDao.GetById(target_id);
                if (tt != null)
                {
                    iconName = tt.icon;
                    quality = tt.quality;
                }
            }
        }

        else if (id.StartsWith(TableConst.frag_war))
        {
            itemType = UIItemType.HeroFrag;
            var tablefrag = DictDataManager.Instance.tableFragDao.GetById(id);
            if (tablefrag != null)
            {
                var target_id = tablefrag.target;
                var th = DictDataManager.Instance.tableHeroDao.GetById(target_id);
                if (th != null)
                {
                    iconName = th.iconName;
                    quality = th.quality;
                }
            }
        }
        else if (id.StartsWith(TableConst.MineItem))
        {
            itemType = UIItemType.Mine;
            var tablemine = DictDataManager.Instance.tableMineSkillDao.GetById(id);
            if (tablemine != null)
            {
                iconName = id;
                quality = -1;
            }
        }
        else if (id.StartsWith(TableConst.FishItem))
        {
            itemType = UIItemType.Fish;
            var tablefish = DictDataManager.Instance.tableFishSkillDao.GetById(id);
            if (tablefish != null)
            {
                iconName = id;
                quality = -1;
            }
        }
        else if (id == TableConst.coin)
        {
            iconName = "item_icon_200";
            itemType = UIItemType.Coin;
            quality = -1;
        }
        else if (id == TableConst.diamond)
        {
            iconName = "item_icon_201";
            itemType = UIItemType.Diamond;
            quality = -1;
        }
        else if (id == TableConst.light)
        {
            iconName = "item_icon_033";
            itemType = UIItemType.Light;
            quality = -1;
        }
        else if (id == TableConst.popularity)
        {
            iconName = TableConst.popularity;
            itemType = UIItemType.Popularity;
            quality = -1;
        }
        else if (id == TableConst.exp)
        {
            iconName = TableConst.exp;
            itemType = UIItemType.exp;
            quality = -1;
        }
        else if (id == TableConst.point)
        {
            iconName = TableConst.point;
            itemType = UIItemType.Point;
            quality = -1;
        }
        else if (id == TableConst.score)
        {
            iconName = TableConst.score;
            itemType = UIItemType.Score;
            quality = -1;
        }
        else if(id == TableConst.contribution)
        {
            iconName = TableConst.contribution;
            itemType = UIItemType.Contribution;
            quality = -1;
        }
        else
        {
            Debug.LogError("Item id parse error id: " + id);
            iconName = "";
            itemType = UIItemType.NONE;
            quality = -1;
        }

    }

    /// <summary>
    /// 通过品质获取边框
    /// </summary>
    /// <param name="quality"></param>
    /// <returns></returns>
    public static string GetQualityFrame(QualityValue quality)
    {
        switch (quality)
        {
            case QualityValue.WHITE:
                return "UI_kuang_big_bian_white";
            case QualityValue.GREEN:
                return "UI_kuang_big_bian_green";
            case QualityValue.BLUE:
                return "UI_kuang_big_bian_blue";
            case QualityValue.PURPLE:
                return "UI_kuang_big_bian_zi";
            case QualityValue.YELLOW:
                return "UI_kuang_big_bian_yellow";
            case QualityValue.RED:
                return "UI_kuang_big_bian_red";
            default:
                return "UI_kuang_big_bian_white";
        }
    }
    /// <summary>
    /// 通过品质获取icon底图
    /// </summary>
    /// <param name="quality"></param>
    /// <param name="circle">圆底</param>
    /// <returns></returns>
    public static string GetQualityBack(QualityValue quality, bool isCircle = false)
    {
        if (!isCircle)
        {
            switch (quality)
            {
                case QualityValue.WHITE:
                    return "UI_kuang_big_di_white";
                case QualityValue.GREEN:
                    return "UI_kuang_big_di_green";
                case QualityValue.BLUE:
                    return "UI_kuang_big_di_blue";
                case QualityValue.PURPLE:
                    return "UI_kuang_big_di_zi";
                case QualityValue.YELLOW:
                    return "UI_kuang_big_di_yellow";
                case QualityValue.RED:
                    return "UI_kuang_big_di_red";
                default:
                    return "UI_kuang_big_di_white";
            }
        }
        else
        {
            switch (quality)
            {
                case QualityValue.WHITE:
                    return "UI_kuang_big_yuandi_white";
                case QualityValue.GREEN:
                    return "UI_kuang_big_yuandi_green";
                case QualityValue.BLUE:
                    return "UI_kuang_big_yuandi_blue";
                case QualityValue.PURPLE:
                    return "UI_kuang_big_yuandi_zi";
                case QualityValue.YELLOW:
                    return "UI_kuang_big_yuandi_yellow";
                case QualityValue.RED:
                    return "UI_kuang_big_yuandi_red";
                default:
                    return "UI_kuang_big_yuandi_white";
            }
        }
    }
    /// <summary>
    /// 通过品质获取碎片图标名称
    /// </summary>
    /// <param name="quality"></param>
    /// <returns></returns>
    public static string GetQualityFrag(QualityValue quality)
    {
        switch (quality)
        {
            case QualityValue.WHITE:
                return "UI_kuang_sui_white";
            case QualityValue.GREEN:
                return "UI_kuang_sui_green";
            case QualityValue.BLUE:
                return "UI_kuang_sui_blue";
            case QualityValue.PURPLE:
                return "UI_kuang_sui_zi";
            case QualityValue.YELLOW:
                return "UI_kuang_sui_yellow";
            case QualityValue.RED:
                return "UI_kuang_sui_red";
            default:
                return "UI_kuang_sui_white";
        }
    }
    /// <summary>
    /// 显示物品的介绍页
    /// </summary>
    /// <param name="type"></param>
    /// <param name="id"></param>
    public static void ShowDescription(UIItemType type, string id)
    {
        switch (type)
        {
            case UIItemType.Hero:
                {
                    TableHero heroData = DictHeroBlo.GetTableHero(id);
                    if (heroData.heroClass != (int)HeroClass.Exp_Eater)
                        PageManager.Instance.OpenPage("UIHeroPage", "heroId=" + id);
                    else
                    {
                        int count = 0;
                        List<UIHero> list = StaticData.playerData.InstPlayerData.GetUIHeros(id);
                        if (list != null)
                            count = list.Count;
                        PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + count.ToString());
                    }
                }
                break;
            case UIItemType.HeroFrag:
                PageManager.Instance.OpenPage("UIHeroPage", "heroId=" + id);
                break;
            case UIItemType.Equip:
                PageManager.Instance.OpenPage("EquipmentUIPage", "equipId=" + id + "&type=1");
                break;
            case UIItemType.EquipFrag:
                PageManager.Instance.OpenPage("EquipmentUIPage", "equipId=" + DictFragBlo.GetTableFrag(id).target + "&type=1");
                break;
            case UIItemType.Treasure:
                PageManager.Instance.OpenPage("EquipmentUIPage", "equipId=" + id + "&type=2");
                break;
            case UIItemType.TreasureFrag:
                PageManager.Instance.OpenPage("EquipmentUIPage", "equipId=" + DictFragBlo.GetTableFrag(id).target + "&type=2");
                break;
            case UIItemType.Item:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.GetSimpleItemCount(id));
                break;
            case UIItemType.Mine:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.GetMineItemCount(id));
                break;
            case UIItemType.Fish:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.GetFishItemCount(id));
                break;
            case UIItemType.Coin:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.coin);
                break;
            case UIItemType.Diamond:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.diamond);
                break;
            case UIItemType.Popularity:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.prestige);
                break;
            case UIItemType.Light:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.retentionLight);
                break;
            case UIItemType.Score:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.bossScore);
                break;
            case UIItemType.Point:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.strategyScore);
                break;
            case UIItemType.Contribution:
                PageManager.Instance.OpenPage("ItemDetailPage", "id=" + id + "&num=" + StaticData.playerData.contribution);
                break;
                

        }
    }

    #region 激活缘分
    static string luckNameColor = "[3c3c3c]{0}[-]";
    static string helperColor = "[3c2011]{0}[-]";
    #endregion

    #region 未激活缘分
    static string luckNameColor0 = "[000000]{0}[-]";
    static string helperColor0 = "[0072ff]{0}[-]";
    #endregion

    /// <summary>
    /// 羁绊描述字体
    /// </summary>
    /// <returns></returns>
    public static string GetLuckDesTex(string luckId, bool actived)
    {
        string des = "";
        string desTemplate = "";

        //List<string> effects = new List<string>();

        string attStr, defStr, lifeStr;

        attStr = TableTextBlo.GetText("word_att");
        defStr = TableTextBlo.GetText("word_def");
        lifeStr = TableTextBlo.GetText("word_hp");

        string helperStr = "";
        string effectStr = "";
        bool heroLuck = false;
        var luck = Dict.DictDataManager.Instance.tableYuanDao.GetById(luckId);
        if (!string.IsNullOrEmpty(luck.hero0) ||
            !string.IsNullOrEmpty(luck.hero1) ||
            !string.IsNullOrEmpty(luck.hero2) ||
            !string.IsNullOrEmpty(luck.hero3))
        {
            desTemplate = TableTextBlo.GetText("luck_text_template");

            if (!string.IsNullOrEmpty(luck.hero0))
            {
                var heroName = TableTextBlo.GetText(Dict.DictDataManager.Instance.tableHeroDao.GetById(luck.hero0).name);
                if (!actived)
                {
                    heroName = "[" + FontColor.Get(Dict.DictDataManager.Instance.tableHeroDao.GetById(luck.hero0).quality) + "]" + heroName + "[-]";
                }
                helperStr += "," + heroName;
            }
            if (!string.IsNullOrEmpty(luck.hero1))
            {
                var heroName = TableTextBlo.GetText(Dict.DictDataManager.Instance.tableHeroDao.GetById(luck.hero1).name);
                if (!actived)
                {
                    heroName = "[" + FontColor.Get(Dict.DictDataManager.Instance.tableHeroDao.GetById(luck.hero1).quality) + "]" + heroName + "[-]";
                }
                helperStr += "," + heroName;
            }
            if (!string.IsNullOrEmpty(luck.hero2))
            {
                var heroName = TableTextBlo.GetText(Dict.DictDataManager.Instance.tableHeroDao.GetById(luck.hero2).name);
                if (!actived)
                {
                    heroName = "[" + FontColor.Get(Dict.DictDataManager.Instance.tableHeroDao.GetById(luck.hero2).quality) + "]" + heroName + "[-]";
                }
                helperStr += "," + heroName;
            }
            if (!string.IsNullOrEmpty(luck.hero3))
            {
                var heroName = TableTextBlo.GetText(Dict.DictDataManager.Instance.tableHeroDao.GetById(luck.hero3).name);
                if (!actived)
                {
                    heroName = "[" + FontColor.Get(Dict.DictDataManager.Instance.tableHeroDao.GetById(luck.hero3).quality) + "]" + heroName + "[-]";
                }
                helperStr += "," + heroName;
            }

            heroLuck = true;
        }
        else
        {
            desTemplate = TableTextBlo.GetText("luck_text_template_equip");

            if (!string.IsNullOrEmpty(luck.equip0))
            {
                var equipName = TableTextBlo.GetText("name_" + luck.equip0);
                if (!actived)
                {
                    equipName = "[" + FontColor.Get(Dict.DictDataManager.Instance.tableEquipDao.GetById(luck.equip0).quality) + "]" + equipName + "[-]";
                }
                helperStr += "," + equipName;

            }
            if (!string.IsNullOrEmpty(luck.treaId0))
            {
                var treaName = TableTextBlo.GetText("name_" + luck.treaId0);
                if (!actived)
                {
                    treaName = "[" + FontColor.Get(Dict.DictDataManager.Instance.tableTreasureDao.GetById(luck.treaId0).quality) + "]" + treaName + "[-]";
                }
                helperStr += "," + treaName;
            }

            heroLuck = false;
        }

        if (!string.IsNullOrEmpty(helperStr))
        {
            helperStr = helperStr.Substring(1);
        }

        if (luck.peratt != 0.0)
        {
            effectStr += (luck.peratt > 0.0 ? ",+" : ",-") + "" + luck.peratt + "%" + attStr;
        }
        if (luck.perdef != 0.0)
        {
            effectStr += (luck.perdef > 0.0 ? ",+" : ",-") + "" + luck.perdef + "%" + defStr;
        }
        if (luck.perhp != 0.0)
        {
            effectStr += (luck.perhp > 0.0 ? ",+" : ",-") + "" + luck.perhp + "%" + lifeStr;
        }

        if (!string.IsNullOrEmpty(effectStr))
        {
            effectStr = effectStr.Substring(1);
        }

        string strColorHelper = string.Format(actived ? helperColor : helperColor0, helperStr);
        string strColorEffct = effectStr;

        if (actived)
        {
            if (heroLuck)
            {
                string luckName = string.Format(luckNameColor, TableTextBlo.GetText(luck.yuanName));
                des = string.Format(desTemplate, luckName, "[be5514]", strColorHelper + "", strColorEffct, "[-]");
            }
            else
            {
                string str = string.Format(desTemplate, TableTextBlo.GetText(luck.yuanName), "[be5514]", strColorHelper + "", strColorEffct, "[-]");
                des = string.Format(luckNameColor, str);
            }
        }
        else
        {
            if (heroLuck)
            {
                string str = string.Format(desTemplate, TableTextBlo.GetText(luck.yuanName), "", strColorHelper + "", strColorEffct, "");
                des = string.Format(luckNameColor, str);
            }
            else
            {
                string str = string.Format(desTemplate, TableTextBlo.GetText(luck.yuanName), "", strColorHelper + "", strColorEffct, "");
                des = string.Format(luckNameColor0, str);
            }
        }

        return des;
    }

    public static GameObject ShowGetObjs(ResultObject objs, string title = "", bool isHidePanel = true)
    {
        GameObject obj = AssetLoad.ResourceManager.Instance.LoadResource("prefab/ShowGet") as GameObject;
        GameObject showget = Object.Instantiate(obj);
        showget.GetComponent<ShowGet>().SetGets(objs, title, isHidePanel);
        showget.transform.parent = PageManager.Instance.transform;
        showget.transform.localPosition = Vector3.zero;
        showget.transform.localScale = Vector3.one;
        return showget;
    }

    public static void ShowGetObjs(List<BaseResource> objs, string title = "")
    {
        GameObject obj = AssetLoad.ResourceManager.Instance.LoadResource("prefab/ShowGet") as GameObject;
        GameObject showget = Object.Instantiate(obj);
        showget.GetComponent<ShowGet>().SetGets(objs, title);
        showget.transform.parent = PageManager.Instance.transform;
        showget.transform.localPosition = Vector3.zero;
        showget.transform.localScale = Vector3.one;

    }

    public static bool GetModuleOpen(string id)
    {
        return DictModuleBlo.GetTableModule(id).openLev <= StaticData.playerData.level;
    }

    public static string GetHeroName(string heroId)
    {
        var hero = Dict.Blo.DictHeroBlo.GetTableHero(heroId);
        if (hero != null)
        {
            if (hero.heroClass == (int)HeroClass.Main_Actor_Man || hero.heroClass == (int)HeroClass.Main_Actor_Woman)
            {
                return StaticData.playerData.name;
            }
            else
            {
                return TableTextBlo.GetText(hero.name);
            }
        }
        else
        {
            return null;
        }
    }

    public static string GetAssetNameFromAssetBundleName(string abName)
    {
        return abName.Substring(abName.LastIndexOf(@"/") + 1);
    }

    public static string GetNameColorByKillNumber(int kills, string name = "{0}")
    {
        string ret = "";
        if (0 <= kills && kills <= 5)
            ret = "[FFFFFF]" + name + "[-]";
        else if (6 <= kills && kills <= 10)
            ret = "[000000]" + name + "[-]";
        else if (11 <= kills && kills <= 20)
            ret = "[000000]" + name + "[-]";
        else if (21 <= kills && kills <= 30)
            ret = "[000000]" + name + "[-]";
        else if (kills >= 31)
            ret = "[FF0000]" + name + "[-]";

        return ret;
    }

    public static string GetHeroAttributePropName(string prop)
    {
        switch (prop)
        {
            case TableConst.Hp:
                return TableTextBlo.GetText("word_hp");
            case TableConst.Attack:
                return TableTextBlo.GetText("word_att");
            case TableConst.MagicDefend:
                return TableTextBlo.GetText("word_mdef");
            case TableConst.PhyDefend:
                return TableTextBlo.GetText("word_pdef");
            case TableConst.hit:
                return TableTextBlo.GetText("word_hit");
            case TableConst.dodge:
                return TableTextBlo.GetText("word_dodge");
            case TableConst.cri:
                return TableTextBlo.GetText("word_cri");
            case TableConst.antiCri:
                return TableTextBlo.GetText("word_antiCri");
            case TableConst.damageAdd:
                return TableTextBlo.GetText("word_damageAdd");
            case TableConst.damageReduce:
                return TableTextBlo.GetText("word_damageReduce");
            default:
                return "";
        }
    }
    public static Vector3 ExtractTranslationFromMatrix(ref Matrix4x4 matrix)
    {
        Vector3 translate;
        translate.x = matrix.m03;
        translate.y = matrix.m13;
        translate.z = matrix.m23;
        return translate;

    }


    public static Quaternion ExtractRotationFromMatrix(ref Matrix4x4 matrix)
    {
        Vector3 forward;
        forward.x = matrix.m02;
        forward.y = matrix.m12;
        forward.z = matrix.m22;

        Vector3 upwards;
        upwards.x = matrix.m01;
        upwards.y = matrix.m11;
        upwards.z = matrix.m21;

        return Quaternion.LookRotation(forward, upwards);
    }

    public static Vector3 ExtractScaleFromMatrix(ref Matrix4x4 matrix)
    {
        Vector3 scale;
        scale.x = new Vector4(matrix.m00, matrix.m10, matrix.m20, matrix.m30).magnitude;
        scale.y = new Vector4(matrix.m01, matrix.m11, matrix.m21, matrix.m31).magnitude;
        scale.z = new Vector4(matrix.m02, matrix.m12, matrix.m22, matrix.m32).magnitude;
        return scale;
    }


    public static void ShowPopupUpTextObj(ResultObject objs)
    {
        string str0 = TableTextBlo.GetText("get_result_obj");
        string str = "";
        //hero
        foreach (var item in objs.wars)
        {
            str += "," + GetResult(item.id) + "x1";
        }


        //equip
        foreach (var item in objs.equips)
        {
            str += "," + GetResult(item.equipId) + "x1";
        }

        //treasure
        foreach (var item in objs.treas)
        {
            str += "," + GetResult(item.treasureId) + "x1";
        }
        //simpleGoods
        foreach (var item in objs.simps)
        {
            str += "," + GetResult(item.id) + "x" + item.num;
        }

        str = str.Substring(1);

        BoxManager.CreatePopupTextBox(string.Format(str0, str));
    }

    public static string GetResult(string id)
    {
        string str = "";
        UIItemType type;
        string iconName;
        int quality;
        CommonMethod.IconParse(id, out type, out iconName, out quality);

        switch (type)
        {
            case UIItemType.NONE:
                break;
            case UIItemType.Hero:
                str = TableTextBlo.GetText(Dict.Blo.DictHeroBlo.GetTableHero(id).name);
                break;
            case UIItemType.HeroFrag:
            case UIItemType.EquipFrag:
            case UIItemType.TreasureFrag:
                str = GetFragName(id);
                break;
            case UIItemType.Equip:
                str = TableTextBlo.GetText("name_" + id);
                break;
            case UIItemType.Treasure:
                str = TableTextBlo.GetText("name_" + id);
                break;
            case UIItemType.Item:
                str = TableTextBlo.GetText("name_" + id);
                break;
            case UIItemType.Coin:
                str = TableTextBlo.GetText("coin");
                break;
            case UIItemType.Diamond:
                str = TableTextBlo.GetText("diamond");
                break;
            case UIItemType.Light:
                str = TableTextBlo.GetText("light");
                break;
            case UIItemType.Popularity:
                str = TableTextBlo.GetText("popularity");
                break;
            case UIItemType.exp:
                str = TableTextBlo.GetText("exp");
                break;
        }

        return str;
    }

    public static Dictionary<string, string> ParseKeyValueEntry(List<KeyValueEntry> entry)
    {
        Dictionary<string, string> dict = new Dictionary<string, string>();

        for (int i = 0; i < entry.Count; i++)
        {
            dict.Add(entry[i].key, entry[i].value);
        }
        return dict;
    }

    /// <summary>
    /// 拥有个数
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public static long GetObjectHaveNum(string id)
    {
        if (id.StartsWith(Dict.Config.TableConst.coin))
            return StaticData.playerData.coin;
        else if (id.StartsWith(Dict.Config.TableConst.diamond))
            return StaticData.playerData.diamond;
        else if (id.StartsWith(Dict.Config.TableConst.popularity))
            return StaticData.playerData.prestige;
        else if (id.StartsWith(Dict.Config.TableConst.score))
            return StaticData.playerData.bossScore;
        else if (id.StartsWith(Dict.Config.TableConst.point))
            return StaticData.playerData.strategyScore;
        else if (id.StartsWith(Dict.Config.TableConst.light))
            return StaticData.playerData.retentionLight;
        else if (id.StartsWith(Dict.Config.TableConst.war))
            return StaticData.playerData.InstPlayerData.GetUIHeros(id).Count;
        else if (id.StartsWith(Dict.Config.TableConst.frag_war))
            return StaticData.playerData.GetFragHeros(id).num;
        else if (id.StartsWith(Dict.Config.TableConst.equip))
            return StaticData.playerData.InstPlayerData.GetUIEquipments(id).Count;
        else if (id.StartsWith(Dict.Config.TableConst.trea))
            return StaticData.playerData.InstPlayerData.GetUITreasures(id).Count;
        else if (id.StartsWith(Dict.Config.TableConst.frag_equip))
            return StaticData.playerData.GetFragEquipments(id).num;
        else if (id.StartsWith(Dict.Config.TableConst.item))
            return StaticData.playerData.GetSimpleItemCount(id);
        else if (id.StartsWith(Dict.Config.TableConst.FishItem))
            return StaticData.playerData.GetFishItemCount(id);
        else if (id.StartsWith(Dict.Config.TableConst.MineItem))
            return StaticData.playerData.GetMineItemCount(id);

        return 0;
    }

    public static string GetShowValue(long v)
    {
        if (v > 99999)
        {
            var a = v / 10000f;
            var _int = (int)a;
            return _int + TableTextBlo.GetText("wan");
        }
        else
        {
            return v.ToString();
        }
    }

    /// <summary>
    /// ParseDiscount
    /// </summary>
    /// <param name="discountText">string 0-100</param>
    /// <returns>discount show value. if 0 means no discount</returns>
    public static float ParseDiscount(string discountText)
    {
        float discount = 0f;
        int discountVal = 0;
        if (!string.IsNullOrEmpty(discountText))
        {
            bool ret = int.TryParse(discountText, out discountVal);
            if (ret)
            {
                discount = (float)discountVal / 10f;
            }
        }
        return discount;
    }


    public static bool CompareVersion(string remoteAppVersion, string remoteResVersion, string localAppVersion, string localResVersion)
    {
        if (remoteResVersion != localResVersion || remoteAppVersion != localAppVersion)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    public static Vector3 GetPosition(string str)
    {
        var sss = str.Trim().Split(new char[1] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
        var x = float.Parse(sss[0]);
        var y = float.Parse(sss[1]);
        var z = float.Parse(sss[2]);

        return new Vector3(x, y, z);
    }

    public static Vector2 GetPoint(string str)
    {
        var sss = str.Trim().Split(new char[1] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
        var x = float.Parse(sss[0]);
        var z = float.Parse(sss[2]);

        return new Vector2(x, z);
    }

    public static string GetUnionNameByCamp(int Camp)
    {
        foreach (ProtoBuf.Message.InstUFUnion instUfUnion in StaticData.unionFightData.unions)
        {
            if (instUfUnion.camp == Camp)
                return instUfUnion.unionName;
            //else
            //    continue;
        }
        return "";
    }
}